
<template>
  <div class="category-list">
    <a-collapse v-model:activeKey="activeKeys" :bordered="false">
      <a-collapse-panel 
        v-for="(items, letter) in categories" 
        :key="letter" 
        :header="letter"
      >
        <a-row :gutter="[8, 8]">
          <a-col :span="8" v-for="item in items" :key="item.code">
            <a-button 
              type="link" 
              :href="item.url" 
              target="_blank"
              class="category-button"
              @click.prevent="$emit('select', item)"
            >
              {{ item.name }}
            </a-button>
          </a-col>
        </a-row>
      </a-collapse-panel>
    </a-collapse>
  </div>
</template>

<script>
import { defineComponent, ref, watchEffect } from 'vue';

export default defineComponent({
  name: 'CategoryList',
  props: {
    categories: {
      type: Object,
      required: true
    }
  },
  emits: ['select'],
  setup(props) {
    const activeKeys = ref([]);
    
    watchEffect(() => {
      activeKeys.value = Object.keys(props.categories);
    });
    
    return {
      activeKeys
    };
  }
});
</script>

<style scoped>
.category-list {
  padding: 0 10px;
}

.category-button {
  width: 100%;
  text-align: left;
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.category-button:hover {
  background-color: #f0f2f5;
  border-radius: 4px;
}
</style>